﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Keepo.Models;
using System.ComponentModel.DataAnnotations;

namespace AlbumDesigner.Models.Types
{
    public class AlbumSectionData
    {
        public int AlbumSectionId { get; set; }
        public string SectionTitle { get; set; }
        public int SectionIdx { get; set; }

        public string EditorPassword { get; set; }

        [RegularExpression(@"\b[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b", ErrorMessage = "דוא\"ל לא תקין")]
        public string EditorEmail { get; set; }
        public string EditorFirstName { get; set; }
        public string EditorLastName { get; set; }
        public string EditorPhone { get; set; }
        public string EditorMobile { get; set; }

        public int PagesCount { get; set; }

        public int AlbumSectionStatusId { get; set; }
        public string AlbumSectionStatus { get; set; }
        public int AlbumSectionLockStatusId { get; set; }
        public string AlbumSectionLockStatus { get; set; }

        public int AlbumSectionTypeId { get; set; }
        public string AlbumSectionType { get; set; }

        public string ShownStatus { get; set; }

        public AlbumSectionData()
        {

        }

        public AlbumSectionData(AlbumSection albumSection)
        {
            this.AlbumSectionId = albumSection.AlbumSectionId;
            this.SectionTitle = albumSection.Title;
            this.SectionIdx = albumSection.SectionIdx;

            this.EditorPassword = albumSection.Editor.Password;
            this.EditorEmail = albumSection.Editor.Email;
            this.EditorFirstName = albumSection.Editor.FirstName;
            this.EditorLastName = albumSection.Editor.LastName;
            this.EditorPhone = albumSection.Editor.Phone;
            this.EditorMobile = albumSection.Editor.Mobile;

            this.PagesCount = albumSection.PagesCount;

            this.AlbumSectionStatusId = albumSection.AlbumSectionStatusId;
            this.AlbumSectionStatus = "-";
            if (albumSection.AlbumSectionStatus != null)
            {
                this.AlbumSectionStatus = albumSection.AlbumSectionStatus.Title;
            }

            this.AlbumSectionLockStatusId = albumSection.AlbumSectionLockStatusId;
            this.AlbumSectionLockStatus = "-";
            if (albumSection.AlbumSectionLockStatus != null)
            {
                this.AlbumSectionLockStatus = albumSection.AlbumSectionLockStatus.Title;
            }

            this.AlbumSectionTypeId = albumSection.AlbumSectionTypeId;
            this.AlbumSectionType = "-";
            if (albumSection.AlbumSectionType != null)
            {
                this.AlbumSectionType = albumSection.AlbumSectionType.Title;
            }

            this.ShownStatus = "-";

            //פתוח   -  לא מאושר
            if (this.AlbumSectionStatusId == 1 && this.AlbumSectionLockStatusId == 3)
            {
                this.ShownStatus = "בעריכה";
            }
            //נעול   -  לא מאושר
            else if (this.AlbumSectionStatusId == 1 && this.AlbumSectionLockStatusId != 3)
            {
                this.ShownStatus = "נעול";
            }
            //נעול מרכזת   -  מאושר תלמיד
            else if (this.AlbumSectionStatusId == 2 && this.AlbumSectionLockStatusId == 2)
            {
                this.ShownStatus = "מאושר תלמיד";
            }
            //נעול דפוס   -  מאושר תלמיד
            else if (this.AlbumSectionStatusId == 2 && this.AlbumSectionLockStatusId == 1)
            {
                this.ShownStatus = "מאושר";
            }
            //נעול
            else if (this.AlbumSectionLockStatusId != 3)
            {
                this.ShownStatus = "מאושר";
            }
        }
    }
}